//同步发送请求的次数
let ajaxTimes = 0

export const request = (params) => {

  ajaxTimes++
  //显示加载中的 效果
  wx.showLoading({
    title: '加载中',
    mask: true
  })

  return new Promise((resolve,reject) => {
    //定义公共url
    const baseUrl = 'https://api-hmugo-web.itheima.net/api/public/v1'
    wx.request({
      ...params,
      url: baseUrl + params.url,
      success: (res) => {
        resolve(res)
      },
      fail: (err) => {
        reject(err)
      },
      complete: () => {
        ajaxTimes--
        if(ajaxTimes === 0) {
          wx.hideLoading()
        }
      }
    })
  })
}